package com.tgh.au.c5;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.KeyEvent;
import android.view.View;

public class GameView extends View {
	private int mCount=0;
	int y=0;
	
	public GameView(Context context) {
		super(context);
		setFocusable(true);
		requestFocus();
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		if (mCount<100) {
			mCount++;
		}else {
			mCount=0;
		}
		Paint paint=new Paint();
		switch (mCount%4) {
		default:
		case 0:
			paint.setColor(Color.BLUE);
			break;
		case 1:
			paint.setColor(Color.GREEN);
			break;
		case 2:
			paint.setColor(Color.RED);
			break;
		case 3:
			paint.setColor(Color.YELLOW);
			break;
		}
		canvas.drawRect((320-80)/2, y, (320-80)/2+80, y+40, paint);
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_DPAD_UP:
			y-=3;
			break;
		case KeyEvent.KEYCODE_DPAD_DOWN:
			y+=3;
			break;
		}
		return true;
	}
}
